package org.inasnet.audio;

import javax.sound.sampled.AudioFormat;

import org.inasnet.Root;
import org.inasnet.user.Session;

/**
 * Class, which provides access to Capture and Playback.
 * @author APtakhin
 *
 */
public class AudioManager 
{
	public static boolean connect( Session session )
	{
		if( mSession == null )
		{
			mSession = session;
			
			mCapture = new Capture();
			mPlayback = new Playback();
			
			mCapture.start();
			mPlayback.start();
			
			return true;
		}
		else
			if( session != null )
			{
				mSession = session;
				
				return true;
			} 
			else return false;
	}
	
	static SessionSoundBuffer getSessionSoundBuffer()
	{
		return mSession.getSoundBuffer();
	}
	
	public static SessionSoundBuffer.InputSound getSessionInputStream()
	{
		return getSessionSoundBuffer().getInputSound();
	}
	
	public static SessionSoundBuffer.OutputSound getSessionOutputStream()
	{
		return getSessionSoundBuffer().getOutputSound();
	}
	
	static Capture mCapture;
	static Playback mPlayback;
	
	static Session mSession;
	
	public final static int bufSize = 16384;
	
	public static AudioFormat format = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, 
			8000, 16, 2, (16/8)*2, 8000, true );
}
